<#assign module="sys"/>

<@override name="header">
</@override>
<@override name="body">

<style>
    div.ac > ul > li > div span em {color:red;font-style: normal;}
</style>
<div class="row">
    <div class="col-xs-12">
        <button class="pull-right btn btn-primary create"><i class="icon-plus"></i>添加结算周期</button>
    </div>
</div>
<div class="row margin-top">
    <div class="col-xs-12">
        <div class="panel panel-primary">
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <thead>
                    <tr style="font-size:14px;">
                        <th>结算机构名称</th>
                        <th>结算周期(天)</th>
                        <th>类型(银行,非银行)</th>
                        <th>支付机构或支付业务许可证编号</th>
                        <th>支付业务类型</th>
                        <th>业务覆盖范围</th>
                        <th>备付金存管银行</th>
                        <th>是否有效</th>
                        <th>操作</th>

                    </tr>
                    </thead>
                    <tbody id="settleAccountsCycleContent">
                        <#if (page.content)?? >
                            <#list page.content as data>
                            <tr>
                                <td>${data.agency?if_exists}</td>
                                <td>${data.bankCyclePeriod?if_exists}</td>
                                <td><#if data.agencyType == "N_BANK">非银行<#else>银行</#if></td>
                                <td>${data.bankAndLicence?if_exists}</td>
                                <td>${data.payType?if_exists}</td>
                                <td>${data.serviceRange?if_exists}</td>
                                <td>${data.reserveBank?if_exists}</td>
                                <td><#if data.valid==1>有效<#else>无效</#if></td>
                                <td>
                                    <a href="javascript:;" data-value="${data.id}" class="btn-link red deletethis">删除</a>
                                </td>
                            </tr>
                            </#list>
                        </#if>
                    </tbody>
                </table>
                <#if page.totalElements??>
                    <ul class="pagination pull-right pagination-sm">
                        <li><a>共 ${page.totalElements} 条数据</a></li>
                        <@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/settle/list">
                            <@pg.index>
                                <@pg.first>
                                    <li><a href="${pageUrl}">&laquo;</a></li>
                                </@pg.first>
                                <@pg.prev>
                                    <li><a href="${pageUrl}">&lsaquo;</a></li>
                                </@pg.prev>
                                <@pg.pages>
                                    <#if  currentPageNumber == pageNumber >
                                        <li class="active"><a href="#">${pageNumber}</a></li>
                                    <#else>
                                        <li><a href="${pageUrl}">${pageNumber}</a></li>
                                    </#if>
                                </@pg.pages>
                                <@pg.next>
                                    <li><a href="${pageUrl}">&rsaquo;</a></li>
                                </@pg.next>
                                <@pg.last>
                                    <li><a href="${pageUrl}">&raquo;</a></li>
                                </@pg.last>
                            </@pg.index>
                        </@pg.pager>
                    </ul>
                </#if>
            </div>
        </div>
    </div>
</div>

<!--添加-->
<div class="form-horizontal">
    <div class="modal fade" id="dialog_create" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="false">&times;</button>
                    <h4 class="modal-title">添加</h4>
                </div>
                <div class="modal-body">
                    <form action="" id="create_from"  method="post">
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>结算机构名称:</label>
                            <div class="col-sm-9">
                                <input id="agency" name="agency" class="form-control" ></input>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>结算周期(天):</label>
                            <div class="col-sm-9">
                                <input id="bankCyClePeriod" name="bankCyclePeriod" type="number" min="1" class="form-control" placeholder=""></input>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>类型:</label>
                            <div class="col-sm-9">
                               <select name="agencyType" id="agencyType" class="form-control">
                                   <option value="BANK">银行</option>
                                   <option value="N_BANK" selected="selected" >非银行</option>
                               </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>支付机构名称:</label>
                            <div id="text_div" class="col-sm-9">
                                <input class="form-control" id="bankAndLicence" name="bankAndLicence" placeholder="或者是支付机构支付业务许可证编号"  type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>支付业务类型:</label>
                            <div id="text_div" class="col-sm-9">
                                <input class="form-control" id="payTyep" name="payType" placeholder=""  type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>业务覆盖范围:</label>
                            <div id="text_div" class="col-sm-9">
                                <input class="form-control" id="serviceRange" name="serviceRange" placeholder=""  type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>备付金存管银行:</label>
                            <div id="text_div" class="col-sm-9">
                                <input class="form-control" id="reserveBank" name="reserveBank" placeholder=""  type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><em>*</em>是否有效:</label>
                            <div class="col-sm-9">
                                <select name="valid" class="form-control">
                                    <option value="0">无效</option>
                                    <option value="1" selected="selected" >有效</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-5">
                            </div>
                            <div class="col-sm-3">
                                <input  type="button" class="btn btn-primary" id="save" value="确定">
                                <button type="button" class="btn btn-default" data-dismiss="modal" id="close_modal">关闭</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>




</@override>
<@override name="footer">
<script type="text/javascript">
    var thisButton;
    $(function(){
        $(".create").click(function(){
            $("#dialog_create").modal();
        });

        $("#save").click(function(){
            if($("#agency").val().trim()== ""){
                $.scojs_message("结算机构名称不能为空", $.scojs_message.TYPE_ERROR);
                return false;
            }else{
            	if($("#agency").val().trim().length > 50){
            		$.scojs_message("结算机构名称长度超出50个字符", $.scojs_message.TYPE_ERROR);
                	return false;
            	}
            }
            if($("#bankCyClePeriod").val().trim()== ""){
                $.scojs_message("结算周期不能为空", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if($("#agencyType").val().trim()== ""){
                $.scojs_message("类型不能为空", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if($("#bankAndLicence").val().trim()== ""){
                $.scojs_message("支付机构名称不能为空", $.scojs_message.TYPE_ERROR);
                return false;
            }else{
            	if($("#bankAndLicence").val().trim().length > 50){
            		$.scojs_message("支付机构名称长度超出50个字符", $.scojs_message.TYPE_ERROR);
                	return false;
            	}
            }
            if($("#payTyep").val().trim()== ""){
                $.scojs_message("支付业务类型不能为空", $.scojs_message.TYPE_ERROR);
                return false;
            }else{
            	if($("#payTyep").val().trim().length > 50){
            		$.scojs_message("支付业务类型长度超出50个字符", $.scojs_message.TYPE_ERROR);
                	return false;
            	}
            }
            if($("#serviceRange").val().trim()== ""){
                $.scojs_message("业务覆盖范围不能为空", $.scojs_message.TYPE_ERROR);
                return false;
            }else{
            	if($("#serviceRange").val().trim().length > 50){
            		$.scojs_message("业务覆盖范围长度超出50个字符", $.scojs_message.TYPE_ERROR);
                	return false;
            	}
            }
            if($("#reserveBank").val().trim()== ""){
                $.scojs_message("备付金存管银行不能为空", $.scojs_message.TYPE_ERROR);
                return false;
            }else{
            	if($("#reserveBank").val().trim().length > 50){
            		$.scojs_message("备付金存管银行长度超出50个字符", $.scojs_message.TYPE_ERROR);
                	return false;
            	}
            }

            $.post("${ctx}/settle/create",$("#create_from").serialize(),function(data){
                if(data.success){
                    $.scojs_message(data.message, $.scojs_message.TYPE_OK);
                    $("#dialog_create").modal("hide");
                    window.location.href='${ctx}/settle/list'
                }else{
                    $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                }

            })

        });




    });



    function deleteSettleAccountsCycle() {
        $.post('${ctx}/settle/delete',{'id':thisButton.attr("data-value")},function(data){
            if(data.success){
                thisButton.parent().parent().remove();
                location.reload(true);
                $.scojs_message('删除成功', $.scojs_message.TYPE_OK);
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
        },'json');
    }
    $(document).ready(function(){
        $(document).on("click",".deletethis",function(){
            thisButton = $(this);
            var confirm = $.scojs_confirm({
                content: "你真的要删除该结算周期吗？",
                action:deleteSettleAccountsCycle
            });
            confirm.show();
        });
    });
</script>
</@override>
<@extends name="../layout.ftl"/>
